/*
 * Settings.java
 *
 * Created on 2 mei 2008, 20:45
 */

package client.gui;

import client.gui.controls.kleurschema.KleurFont;
import client.gui.controls.kleurschema.KleurVakje;
import client.gui.controls.kleurschema.Kleurenschemas;
import client.gui.controls.scrabble.Vakje;
import java.awt.*;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.net.URI;
import javax.swing.*;


/**
 *
 * @author  Gonyo
 */
public class Settings extends javax.swing.JFrame {
      JPanel paneelVelden = new JPanel();
      //JPanel paneelBlokjes = new JPanel();
      JPanel paneel = new JPanel();
      JComboBox cmb_kleurenschemas = new JComboBox();
      KleurVakje wm3= new KleurVakje(new Vakje(Vakje.Type.DRIE_MAAL_WOORDWAARDE));
      KleurVakje wm2=new KleurVakje(new Vakje(Vakje.Type.TWEE_MAAL_WOORDWAARDE));
      KleurVakje lm3=new KleurVakje(new Vakje(Vakje.Type.DRIE_MAAL_LETTERWAARDE));
      KleurVakje lm2=new KleurVakje(new Vakje(Vakje.Type.TWEE_MAAL_LETTERWAARDE));
      KleurVakje nrm=new KleurVakje(new Vakje(Vakje.Type.NORMAAL));
      KleurVakje mid = new KleurVakje(new Vakje(Vakje.Type.MIDDEN));
      KleurFont font = new KleurFont(new Vakje(Vakje.Type.NORMAAL).getForeground(),this);
      
    //  KleurBlokje ngb;
    //  KleurBlokje gb;
    //  KleurBlokje bb;
      
    
    /** Creates new form Settings */
    public Settings() {
        
        initComponents();
        /*
        Blokje b = new Blokje("B");
        
        ngb =  new KleurBlokje(b);
        
        b.setGevalideerd(true);
        bb=  new KleurBlokje(b);
        
        b = new Blokje("?");
        b.setBlancoBlokje(true);
        gb =  new KleurBlokje(b);
     */

        cmb_kleurenschemas.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBox1ItemStateChanged(evt);
            }
        });
        cmb_kleurenschemas.addItem("Default");
        cmb_kleurenschemas.addItem("Twilight");
        cmb_kleurenschemas.addItem("Classy");        
        cmb_kleurenschemas.addItem("MijnStijl");
        cmb_kleurenschemas.addItem("Flashy");
        cmb_kleurenschemas.setSelectedItem(Kleurenschemas.getInstance().getFile());
        
        paneelVelden.add(cmb_kleurenschemas);
        
        paneelVelden.add(font);
        
        paneelVelden.add(wm3);
        paneelVelden.add(wm2);
        paneelVelden.add(lm3);
        paneelVelden.add(lm2);
        paneelVelden.add(nrm);
        paneelVelden.add(mid);
        
        paneelVelden.setPreferredSize(new Dimension (450,620));
        /*
        paneelBlokjes.add(ngb);
        paneelBlokjes.add(bb);
        paneelBlokjes.add(gb);
        paneelBlokjes.setPreferredSize(new Dimension (450,500));
        */
        paneel.add(paneelVelden);
      //  paneel.add(paneelBlokjes);
        JButton ok = new JButton("OK");
        ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okActionPerformed(evt);
            }
        });
        JButton annuleren = new JButton("Annuleren");
        annuleren.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                anulerenActionPerformed(evt);
            }
        });
        
        paneel.add(ok);
        paneel.add(annuleren);
        
        this.setPreferredSize(new Dimension (450,700));
        this.setContentPane(paneel);
        this.pack();
    }

    public void toon() {
        setVisible(true);
    }
      private void okActionPerformed(java.awt.event.ActionEvent evt) {
         try{
            // Create file 
              URI uri = new URI(Kleurenschemas.getInstance().getKleurschemapad() + "MijnStijl.conf");
            String s = uri.getPath();
            FileWriter fstream = new FileWriter(s);
            BufferedWriter out = new BufferedWriter(fstream);
            out.write(wm3.getText()+"\n");
            out.write(wm2.getText()+"\n");
            out.write(lm3.getText()+"\n");
            out.write(lm2.getText()+"\n");
            out.write(mid.getText()+"\n");
            out.write(nrm.getText()+"\n");
            out.write(nrm.getText()+"\n");
            out.write(";255;255;204"+"\n");
            out.write(";192;192;192"+"\n");
            out.write(";255;0;0"+"\n");
            out.write(";153;204;255"+"\n");
            out.write(";0;153;153"+"\n");
            out.write(";100;100;100"+"\n");
            out.write(font.getText()+"\n");
            //Close the output stream
            out.close();
            Kleurenschemas.getInstance().laadKleuren("MijnStijl");
            }catch (Exception e){//Catch exception if any
              System.err.println("Error: " + e.getMessage());
            }
         this.dispose();
    }
       private void anulerenActionPerformed(java.awt.event.ActionEvent evt) {
        this.dispose();
    }
       
       public void refreshFont(Color c)
       {
            wm3.setNieuweFontKleur(c);
            wm2.setNieuweFontKleur(c);
            lm3.setNieuweFontKleur(c);
            lm2.setNieuweFontKleur(c);
            nrm.setNieuweFontKleur(c);
            mid.setNieuweFontKleur(c);
       }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();

        jButton1.setText("jButton1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 412, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 552, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {
        String filenaam= cmb_kleurenschemas.getSelectedItem().toString();
        Kleurenschemas.getInstance().laadKleuren(filenaam);
        font.setCol(new Vakje(Vakje.Type.NORMAAL).getForeground());
        font.refresh();
        wm3.refresh();
        wm2.refresh();
        lm3.refresh();
        lm2.refresh();
        nrm.refresh();
        mid.refresh();
        
        /*
        ngb.refresh();
        gb.refresh();
        bb.refresh();
         * */
    }    
    /**
     * @param args the command line arguments
     */
    
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Settings().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    // End of variables declaration//GEN-END:variables
    
}
